<template>
	<view class="floor-item" @click="navToDetailPage">
		<image :src="tempiteminfo.image" mode="aspectFill"></image>
		<text class="title clamp">{{tempiteminfo.name}}</text>
		<view class="pandbtn-bot">
			<text class="price">￥{{ tempUserType==0 ?tempiteminfo.price:tempiteminfo.agentPrice}}</text>
			<image @tap.stop="addCart" class="icon-cart" src="../static/index/cart.png" mode="widthFix"></image>
		</view>
	</view>
</template>

<script>
	export default {
		name: "indproitem1",
		data() {
			return {
				tempiteminfo: this.info,
				tempUserType: this.usertype,
			};
		},

		props: {
			info: Object,
			usertype: String
		},
		methods: {
			//-----------------------------------点击-------------------------------
			/**
			 * 详情跳转
			 */
			navToDetailPage() {
				let id = this.tempiteminfo.id;
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
			//加入购物车
			addCart: function() {
				let than = this;
				if (uni.getStorageSync('userInfo')) {
					than.$api.addCartF(this.tempiteminfo.id, 1, uni.getStorageSync('userInfo').userCode);
				} else {
					than.$api.msg('请先登陆');
				}
			},
		},
		watch: {
			usertype: function(newQuestion, oldQuestion) {
				this.tempUserType = newQuestion;
			}
		}
	}
</script>

<style lang="scss">
	.floor-item {
		width: 204upx;
		margin-right: 20upx;
		font-size: $font-sm+2upx;
		color: $font-color-dark;
		line-height: 1.8;

		image {
			width: 204upx;
			height: 204upx;
			border-radius: 6upx;
		}

		.pandbtn-bot {
			display: flex;
			justify-content: space-between;

			.icon-cart {
				width: 40upx;
				height: 40upx;
				margin: 3upx;
			}
		}

		.price {
			color: $uni-color-primary;
		}
	}
</style>
